package com.louis.testautowired.controller;

import com.louis.testautowired.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * @author XRY
 * @date 2023年06月25日11:11
 */
@Controller
public class UserController {
    //注入service
    //第一种方式：属性注入
//    @Autowired
//    private UserService userService;

//    //第二种方式：set注入
//    private UserService userService;
//    @Autowired
//    public void setUserService(UserService userService) {
//        this.userService = userService;
//    }

//    //第三种方式：构造方法注入
//    private UserService userService;
//
//    @Autowired
//    public UserController(UserService userService) {
//        this.userService = userService;
//    }

//    //第四种方式：形参上进行注入
//    private UserService userService;
//
//    public UserController(@Autowired UserService userService) {
//        this.userService = userService;
//    }

    //第五种方式：类中只有一个构造方法，可以不使用注解
    private UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    public void show(){
        System.out.println("UserController...........");
        userService.show();
    }
}
